// src/plugins/loading.js
import { ElLoading } from "element-plus";

let loadingInstance = null;

const showLoading = (options = {}) => {
  loadingInstance = ElLoading.service({
    fullscreen: true,
    lock: true,
    text: "加载中...",
    background: "rgba(0, 0, 0, 0.7)",
    ...options
  });
};

const hideLoading = () => {
  if (loadingInstance) {
    loadingInstance.close();
    loadingInstance = null;
  }
};

export default {
  install(app) {
    app.config.globalProperties.$showLoading = showLoading;
    app.config.globalProperties.$hideLoading = hideLoading;
  }
};
